import api from '../../common/config/api-url'
import Vue from 'vue'
export default {
  list: data => {
    return new Promise(resolve => {
      Vue.prototype.$u.get(api.address.list, data).then(
        r => {
          if (r && r.code === 0) {
            resolve(r.data)
          }
        },
        e => {
          wx.showToast({
            title: e.msg,
            icon: 'none',
            duration: 2000
          })
        }
      )
    })
  },
  save: data => {
    return new Promise(resolve => {
      Vue.prototype.$u.post(api.address.save, data).then(
        r => {
          if (r && r.code === 0) {
            resolve(r)
          }
        },
        e => {
          wx.showToast({
            title: e.msg,
            icon: 'none',
            duration: 2000
          })
        }
      )
    })
  },
  update: data => {
    return new Promise(resolve => {
      Vue.prototype.$u.post(api.address.update, data).then(
        r => {
          if (r && r.code === 0) {
            resolve(r)
          }
        },
        e => {
          wx.showToast({
            title: e.msg,
            icon: 'none',
            duration: 2000
          })
        }
      )
    })
  },
  setDefault: data => {
    return new Promise(resolve => {
      Vue.prototype.$u.post(api.address.setDefault + '?id=' + data).then(
        r => {
          if (r && r.code === 0) {
            resolve(r)
          }
        },
        e => {
          wx.showToast({
            title: e.msg,
            icon: 'none',
            duration: 2000
          })
        }
      )
    })
  },
  info: data => {
    return new Promise(resolve => {
      Vue.prototype.$u.get(api.address.info + '?id=' + data).then(
        r => {
          if (r && r.code === 0) {
            resolve(r)
          }
        },
        e => {
          wx.showToast({
            title: e.msg,
            icon: 'none',
            duration: 2000
          })
        }
      )
    })
  },
  del: data => {
    return new Promise(resolve => {
      Vue.prototype.$u.post(api.address.del + '?id=' + data).then(
        r => {
          if (r && r.code === 0) {
            resolve(r)
          }
        },
        e => {
          wx.showToast({
            title: e.msg,
            icon: 'none',
            duration: 2000
          })
        }
      )
    })
  }
}
